const app = getApp();
const http = require("../../../../utils/httpUtils.js");
Page({
    data: {
        navbarData: {
            showCapsule: 1, //是否显示左上角图标
            title: '活动列表' //导航栏 中间的标题
        },
        height: app.globalData.height * 2 + 20,
        windowHeight: '',
        currentTab: 0,
        list: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.setData({
            queryData: JSON.parse(options.queryData)
        })
        this.getCateList()
        let that = this;
        wx.getSystemInfo({
            success(res) {
                // console.log(res)
                that.setData({
                    windowHeight: res.windowHeight - that.data.height
                })
            }
        })
    },
    getCateList() { //获取分类
        http._get('/api/GoodsCategory/getCateList', {
            'v': '1.1.0',
            'type': 'category',
            'c_client': 'weixinSmall'
        }, res => {
            if (res.data.code == 1) {
                // console.log(res.data.data)
                this.setData({
                    cateList: res.data.data
                })
                for (let i in res.data.data) {
                    // console.log(res.data.data[i])
                    if (this.data.queryData.gc_id == res.data.data[i].gc_id) {
                        this.setData({
                            currentTab: i
                        })
                        this.getCateGoods(res.data.data[i].gc_id)
                        break;
                    }
                }
            }
        })
    },
    checkCate(e, cateid) {
        let edata = e.currentTarget.dataset;
        this.getCateGoods(edata.id);
        if (this.data.currentTab == edata.index) {
            return false;
        } else {
            this.setData({
                currentTab: edata.index
            })
        }
    },
    detail(e) { //进入商品详情
        let id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: `/pages/public/goods_detail/index?id=${id}`,
        })
    },
    getCateGoods(cateid) {
        let _data = {
            'v': '1.1.0',
            'gc_id': cateid,
            'c_client': 'weixinSmall'
        }
        http._get('/api/GoodsCategory/getCateGoods', _data, res => {
            if (res.data.code == 1) {
                this.setData({
                    list: res.data.data
                })
            }
        })
    }
})